package j.framework.core;

import j.util.SpringBeans;
import j.util.pkgenerator.DefaultPkGeneratorServiceImpl;
import j.util.pkgenerator.PG;
import j.util.pkgenerator.PkGeneratorService;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.sql.DataSource;

//import test.BaiduYunMonitor;

/**
 * User: jason
 * Date: 2014/11/7 16:22
 */
public class WebListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        //初始化PG，即主键生成器
        final DataSource ds = SpringBeans.getBean(DataSource.class);
        PkGeneratorService pkGeneratorService = new DefaultPkGeneratorServiceImpl(ds);
        PG.init(pkGeneratorService);

        /*Timer timer = new Timer(true);
        Date firstTime = new Date();
        firstTime = DateUtils.dateAdd(DateUtils.SECOND, firstTime, 3);
        //每1分钟去数据源中拿一个连接，并执行一个查询，再关闭此连接，若出现异常，则记录到数据库中
        timer.schedule(new BaiduYunMonitor(ds),firstTime,10*60*1000l);
        System.out.println("开始测试百度云推送...");*/
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
